package com.dily.study.demo.thread;

/**
 * Date: 2022-08-09 星期二
 * Time: 16:05
 * Author: Dily_Su
 * Remark:
 * 实现 Runnable接口 重写 run() 实现线程创建
 * new Thread() 调用 start() 方法启动线程
 *
 * 线程开启后不一定立即执行，需要等待 CPU 进行调度
 */
public class TestRunnable implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i<20; i++){
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("我在学习多线程：" + i);
        }
    }


    public static void main(String[] args) {
        TestRunnable testRunnable = new TestRunnable();
        new Thread(testRunnable).start();

        for (int i = 0; i<20; i++){
            System.out.println("我在看代码：" + i);
        }
    }
}